﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using OnlineShop.Models;
using OnlineShop.Common;
using OnlineShop.Models.ViewModels;

namespace OnlineShop.Controllers
{
    public class HomeController : BaseController
    {
        #region Repository
        private IOnlineShopRepository repository;

        public HomeController():this(new EFOnlineShopRepository())
        {
        }

        public HomeController(EFOnlineShopRepository eFOnlineShopRepository)
        {
            this.repository = eFOnlineShopRepository;
        }

        #endregion

        //
        // GET: /Home/
        public ActionResult Index()
        {
            var model = new List<ProductModel>();

            foreach (var item in repository.GetHotProducts())
                model.Add(item.ToModel());

            return View(model);
        }

        [ChildActionOnly]
        public ActionResult LoadHeader()
        {
            if (CurrentUser != null)
                ViewBag.IsLogin = true;
            else
                ViewBag.IsLogin = false;

            ViewData["NumProductInCart"] = Cart.GetQuantityProducts();
            
            return PartialView("Header");
        }
    }
}
